var grid = null;
var form = null;
$(function(){

    form = $("#container").ligerForm();

    grid =  $("#listgrid").ligerGrid({
        width:'100%',
        height:'99%',
        checkbox:true,
        rownumbers: true,
        columns: [
            { display: '所属机构', name: 'deptName'},
            { display: '姓名', name: 'realname' },
            { display: '用户名', name: 'username'},
            { display: '义工证号', name: 'ygcardno' },
            { display: '性别', name: 'sex',
                render:function (item) {
                    if (parseInt(item.sex) == 1) return '男';
                    return '女';
                }
            },
            { display: '培训时长', name: 'traintime' },
            { display: '注册时间', name: 'regtm',
                render:function (item) {
                    if(item.regtm != null) return timestampToTime(item.regtm);
                    return '';
                }
            }
        ],
        pageSize:30,
        pageSizeOptions: [5, 15, 30, 50, 100],
        url:'/member/list'
    });

    $("#search").click(function () {
        var text = $('#keyword').val();
        var param = $('#param').val();
        grid.set({
            pageSize:30,
            pageSizeOptions: [5, 15, 30, 50, 100],
            url:'/member/list',
            parms:[{name:param,value:text}]
        });
    });


    $("#dept").click(function () {
        top.dialog({
            id: 'ztree-dialog',
            title: '请选择组织结构',
            width:300,
            url: '/dept',
            onclose: function() {
                if (this.returnValue) {
                    var selected= $("#param").ligerGetComboBoxManager();
                    selected.setValue('deptName');
                    $('#keyword').val(this.returnValue);
                }
            }
        }).show(this);
        return false;
    });



});

function timestampToTime(tamp) {
    var timestamp4 = new Date(tamp);
    //return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
    return timestamp4.toLocaleDateString().replace(/\//g, "-");
}




